#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"

#define NOISY_TEST 0

void testScoreFor(){
	int i, player;
	int seed = 50;
	int numPlayer = 3;
	struct gameState state, state2;
	//int handScore = 0, discardScore = 0, score = 0;
	int score = 0;
	int cur;
	int k[10] = {adventurer, council_room, feast, gardens, mine,
					remodel, smithy, village, baron, great_hall};

	int r; // = initializeGame(numPlayer, k, seed, &state);

	for(player = 0; player < numPlayer; player++){
		// Duc assisted with modifying function to only buy kingdom cards initialized.
		// Reset game states
		//memset(&state, 23, sizeof(struct gameState));
		score = 0; // reset score
		r = initializeGame(numPlayer, k, seed, &state);
		// copy the current game state before using asserts
		memcpy(&state2, &state, sizeof(struct gameState));
		state.whoseTurn = player; // set players turn
#if (NOISY_TEST == 1)
		printf("Current player: %d\n", player);
#endif
		cur = scoreFor(player, &state2); // use the copied state to run scoreFor
		// score from hand
		for(i = 0; i < state.handCount[player]; i++){
#if (NOISY_TEST == 1)
        	printf("Card %d: %d; ", i, state.hand[player][i]);
#endif
			// the following conditions are taken from scoreFor()
			if(state.hand[player][i] == curse){ score = score - 1;};
			if(state.hand[player][i] == estate){ score = score + 1;};
			if(state.hand[player][i] == duchy){ score = score + 3;};
			if(state.hand[player][i] == province){ score = score + 6;};
			if(state.hand[player][i] == great_hall){ score = score + 1;};
			if(state.hand[player][i] == gardens){ score = score + ( fullDeckCount(player, 0, &state) / 10); };
		}
#if (NOISY_TEST == 1)
		printf("\n");
		printf("Hand score: %d\n", score);
#endif
		// score from discard
		for(i = 0; i < state.discardCount[player]; i++){
			// the following conditions are taken from scoreFor()
			if(state.discard[player][i] == curse){ score = score - 1; };
			if(state.discard[player][i] == estate){ score = score + 1; };
			if(state.discard[player][i] == duchy){ score = score + 3; };
			if(state.discard[player][i] == province){ score = score + 6; };
			if(state.discard[player][i] == great_hall){ score = score + 1; };
			if(state.discard[player][i] == gardens){ score = score + ( fullDeckCount(player, 0, &state) / 10); };
		}
#if (NOISY_TEST == 1)
		printf("Hand + Discard Score: %d\n", score);
#endif
		// score from deck
		for(i = 0; i < state.discardCount[player]; i++){
			// the following conditions are taken from scoreFor()
			if(state.deck[player][i] == curse){ score = score - 1; };
			if(state.deck[player][i] == estate){ score = score + 1; };
			if(state.deck[player][i] == duchy){ score = score + 3; };
			if(state.deck[player][i] == province){ score = score + 6; };
			if(state.deck[player][i] == great_hall){ score = score + 1; };
			if(state.deck[player][i] == gardens){ score = score + ( fullDeckCount(player, 0, &state) / 10); };
		}
#if (NOISY_TEST == 1)
		printf("Hand + Discard + State Score: %d\n", score);
		printf("Calculated score: %d\n\n", cur);
#endif
		// asserts begin here
		assert(score == cur);
	}
	printf("Finishing testScoreFor()\n");
}

int main(){
	testScoreFor();
	return 0;
}
